package me.jessyan.mvparms.demo.di.module.car;

import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.jess.arms.di.scope.ActivityScope;
import com.jess.arms.widget.CustomPopupWindow;

import dagger.Module;
import dagger.Provides;

import me.jessyan.mvparms.demo.R;
import me.jessyan.mvparms.demo.mvp.contract.car.MyCarsContract;
import me.jessyan.mvparms.demo.mvp.model.car.MyCarsModel;
import me.jessyan.mvparms.demo.utils.PerfectClickListener;


@Module
public class MyCarsModule {
    private MyCarsContract.View view;

    /**
     * 构建MyCarsModule时,将View的实现类传进来,这样就可以提供View的实现类给presenter
     *
     * @param view
     */
    public MyCarsModule(MyCarsContract.View view) {
        this.view = view;
    }

    @ActivityScope
    @Provides
    MyCarsContract.View provideMyCarsView() {
        return this.view;
    }

    @ActivityScope
    @Provides
    MyCarsContract.Model provideMyCarsModel(MyCarsModel model) {
        return model;
    }

    @ActivityScope
    @Provides
    CustomPopupWindow unBindPop(){
        View content = LayoutInflater.from(view.getActivity())
                .inflate(R.layout.pop_frag_mine_loginout,null);
        CustomPopupWindow popupWindow = CustomPopupWindow.builder()
                .isFocus(true)
                .isOutsideTouch(true)
                .isWrap(true)
                .contentView(content)

                .customListener(new CustomPopupWindow.CustomPopupWindowListener() {
                    @Override
                    public void initPopupView(View contentView) {
                        TextView titleTv= contentView.findViewById(R.id.pop_title_tv);
                        TextView startTv= contentView.findViewById(R.id.pop_start_tv);
                        titleTv.setText("确定要解绑此车辆？");
                        startTv.setText("解绑");
                        startTv.setOnClickListener(new PerfectClickListener() {
                            @Override
                            protected void onNoDoubleClick(View v) {
                                view.popBackUnBind();
                            }
                        });
                        contentView.setOnClickListener(new PerfectClickListener() {
                            @Override
                            protected void onNoDoubleClick(View v) {
                                view.popDismiss();
                            }
                        });
                    }
                }).build();
        //PopupWindow全屏显示
        popupWindow.setClippingEnabled(false);
        return popupWindow;
    }
}